/*
Menu.h - Library for creating nested Menus with callback functions
Original Author: CWAL
License: Just leave this header, do anything else with it you want

*/
#ifndef Menu_h
#define Menu_h

#include <stdlib.h>
#include <string.h>
#include <math.h>

#define MENU_NAME_LEN 15

#define REFRESH_NOW			1

class Menu{
	public:
	int scroll;
	Menu * parent;//Parent Menu, NULL if this is the top
	Menu * child;//First Child Menu, NULL if no children
	Menu * sibling;//Next Sibling Menu, NULL if this is the last sibling

	void setParent(Menu &p);//Sets the Menu's Parent to p
	void addSibling(Menu &s,Menu &p);//Adds a Sibling s with Parent p.  If the Menu already has a sibling, ask that sibling to add it

	char *name;//Name of this Menu
	char name_str[MENU_NAME_LEN];
	 
	char (*canEnter)(Menu&);//Function to be called when this menu is 'used'
	char (*keyPress)(char);
	char (*display)();
	 
	Menu(char *n);//Constructs the Menu with a name and a NULL use function (be careful calling it)
	//Menu(char *n,char (*c)(Menu&));//Constructs the Menu with a specified use function
	//Menu(char*n, char(*c)(Menu&),char (*k)(char));//constructs a menu for a specified use with a specific display function and a separate keypress.
	Menu(char*n,char(*c)(Menu&),char(*d)(),char(*k)(char)); // can enter, display, keypress.
	void addChild(Menu &c);//Adds the child c to the Menu.  If the menu already has a child, ask the child to add it as a sibling
	void refreshNow();
	Menu * getChild(int which);//Returns a pointer to the which'th child of this Menu
	Menu * getSibling(int howfar);//Returns a pointer to the sibling howfar siblings away from this Menu
	Menu * getParent();//Returns this Menu's parent Menu.  If no parent, returns itself
};

#endif //Menu_h
